package com.zm.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zm.jdbc.AccessDb;

public class LogoutServlet extends HttpServlet {
    
	 private AccessDb db;
	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void service(HttpServletRequest request,HttpServletResponse response){
		HttpSession session=request.getSession(true);
		String name=(String) session.getAttribute("Account");
		db.changeStatus("logout", name);
		session.setAttribute("Login",null);
		session.setAttribute("Account", null);
		try {
			response.sendRedirect("../LoginJsp.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


	public void init(ServletConfig config) throws ServletException {
		ServletContext application=config.getServletContext();
		 if(application.getAttribute("accessdb")==null){
			 db=new AccessDb();
			 application.setAttribute("accessdb",db);
		  }else
			  db=(AccessDb) application.getAttribute("accessdb");
	}

}
